$(document).ready(function(){
	freshMaintains();
});

function showOrderDetail(orderId) {
	requestUrl = "customer_json_servlet";
	var params = {
		request_method:"get_maintain_order_detail",
		order_id:orderId
	};
	
	$.post(requestUrl, params, function(data){
		var orderDetail = data.resultData;
		var maintainItems = orderDetail.maintainItems;
		
		$("#div_maintain_order_detail").html("");
		$("#div_maintain_order_detail").css("display", "");
		var innerHtml = "";

		innerHtml += '<div style="width: 390px; height: 50px; font-size: 15pt; font-weight: bold; border-bottom: 1px solid #c8c8c8;">';
		innerHtml += '		<span style="padding-top: 14px;">我的养护</span>';
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">车牌:</span>';
		innerHtml += '		<span style="width: 150px; display: inline-block; color: blue;">' + orderDetail.licenseNumber + '</span>';
		if (orderDetail.status == 0) {
			innerHtml += '		<img src="../image/btn_cancel_order.png" align="top"/>';
		}
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">状态:</span>';
		innerHtml += ((orderDetail.status == 3) ? '<span style="color:#056a05;">已完成</span>' : '<span style="color:#fc3c3c;">进行中</span>');
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">养护里程数:</span>';
		innerHtml += orderDetail.mileage + "公里";
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">养护日期:</span>';
		innerHtml += '		<span style="width: 150px; display: inline-block;">' + orderDetail.maintainDate + '</span>';
		if (orderDetail.status == 0) {
			innerHtml += '		<img src="../image/btn_change_date.png" align="top"/>';
		}
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">维修店地址:</span>';
		innerHtml += orderDetail.address;
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">养护费用:</span>';
		innerHtml += orderDetail.maintainFee + "元";
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">备注:</span><br/>';
		innerHtml += '<textarea style="width: 379px; height: 113px; border: none; background: url(\'../image/bg_info_textarea.png\') no-repeat;" disabled="disabled">' + orderDetail.comment + '</textarea><br/>';
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 14pt;">';
		innerHtml += '		<span style="width: 115px; display: inline-block;">详细内容:</span>';
		innerHtml += '	</div>';
		innerHtml += '	<div style="padding-top: 15px; font-size: 12pt;">';
		innerHtml += '		<span style="width: 110px; display: inline-block;" align="center">商品名称</span>';
		innerHtml += '		<span style="width: 85px; display: inline-block;" align="center">品牌</span>';
		innerHtml += '		<span style="width: 85px; display: inline-block;" align="center">型号</span>';
		innerHtml += '		<span style="width: 100px; display: inline-block;" align="center">周期</span>';
		innerHtml += '	</div>';
		for(var i = 0; maintainItems && i < maintainItems.length; i++) {
			var item = maintainItems[i];
			
			innerHtml += '	<div style="width: 380px; font-size: 12pt; background: url(../image/bg_maintain_item.png) no-repeat; border-bottom: 1px solid #c4c4c4;">';
			innerHtml += '		<span style="width: 95px; display: inline-block;" align="center">' + item.itemTypeName + '</span>';
			innerHtml += '		<span style="width: 75px; display: inline-block;" align="center">' + item.itemBrandName + '</span>';
			innerHtml += '		<span style="width: 85px; display: inline-block;" align="center">' + item.itemModel + '</span>';
			innerHtml += '		<span style="width: 110px; display: inline-block;" align="center">' + item.itemPeriodName + '</span>';
			innerHtml += '	</div>';
		}
		
		$("#div_maintain_order_detail").html(innerHtml);

		addFadeEffect();
	}, "json");
}

/*
 * 刷新订单列表
 */
function freshMaintains() {
	requestUrl = "customer_json_servlet";
	var params = {
		request_method:"get_maintain_orders",
		car_license:$("#slt_car").val(),
		order_status:$("#slt_status").val()
	};

	$.post(requestUrl, params, function(data){
		var orders = data.resultData;
		var order;
		
		$("#div_maintain_order_detail").css("display", "none");
		$("#div_order_list").html("");
		var innerHtml = "";

		for (var i = 0; orders && i < orders.length; i++) {
			order = orders[i];
			
			innerHtml += '<div style="height: 75px; margin-left: 10px; border-bottom: 1px solid #e1e1e1; cursor: pointer;"';
			innerHtml += '	onclick="showOrderDetail(\'' + order.id + '\');">';
			innerHtml += '	<div>';
			innerHtml += '		<h3 style="padding: 8px 0px;">' + order.licenseNumber + '</h3>';
			innerHtml += '	</div>';
			innerHtml += '	<div>';
			innerHtml += '		<span style="width: 160px; display: inline-block;">养护日期：' + order.maintainDate + '</span>';
			innerHtml += '		<span style="width: 160px; display: inline-block;">养护里程：' + order.mileage + '公里</span>';
			innerHtml += '		<br/>';
			innerHtml += '	</div>';
			innerHtml += '	<div>';
			innerHtml += '		<span style="width: 160px; display: inline-block;">养护费用：' + order.maintainFee + '元</span>';
			innerHtml += '		<span style="width: 160px; display: inline-block;">状态：' + ((order.status == 3) ? '<span style="color:#056a05;">已完成</span>' : '<span style="color:#fc3c3c;">进行中</span>') + '</span>';
			innerHtml += '		<br/>';
			innerHtml += '	</div>';
			innerHtml += '</div>';
		}
		$("#div_order_list").html(innerHtml);
	}, "json");
}